package com.hdaccp.shuiguoD.shiro;

import com.hdaccp.shuiguoD.dao.userDao;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;



public class MyShiroRealm extends AuthorizingRealm {
    @Autowired
    private userDao userDao ;

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
      return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        System.out.println("认证方法......");
        UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken ;
        String username = token.getUsername() ;
        //加载数据库中的密码
        String pwd= userDao.getPwdByUserName(username) ;
        if(pwd == null || "".equals(pwd)){
            return null ;
        }
        AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(username,pwd,"myreal") ;

        return authenticationInfo;
    }
}
